<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - thresholding_abstract.h</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2006  Davis E. King (davis@dlib.net)
</font><font color='#009900'>// License: Boost Software License   See LICENSE.txt for the full license.
</font><font color='#0000FF'>#undef</font> DLIB_THRESHOLDINg_ABSTRACT_
<font color='#0000FF'>#ifdef</font> DLIB_THRESHOLDINg_ABSTRACT_ 

<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../pixel.h.html'>../pixel.h</a>"

<font color='#0000FF'>namespace</font> dlib
<b>{</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>char</u></font> on_pixel <font color='#5555FF'>=</font> <font color='#979000'>255</font>;
    <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>char</u></font> off_pixel <font color='#5555FF'>=</font> <font color='#979000'>0</font>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> in_image_type,
        <font color='#0000FF'>typename</font> out_image_type
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='threshold_image'></a>threshold_image</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> in_image_type<font color='#5555FF'>&amp;</font> in_img,
        out_image_type<font color='#5555FF'>&amp;</font> out_img,
        <font color='#0000FF'>typename</font> pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> image_traits<font color='#5555FF'>&lt;</font>in_image_type<font color='#5555FF'>&gt;</font>::pixel_type<font color='#5555FF'>&gt;</font>::basic_pixel_type thresh
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        requires
            - in_image_type == is an implementation of array2d/array2d_kernel_abstract.h
            - out_image_type == is an implementation of array2d/array2d_kernel_abstract.h
            - pixel_traits&lt;typename image_traits&lt;out_image_type&gt;::pixel_type&gt;::grayscale == true  
            - pixel_traits&lt;typename image_traits&lt;in_image_type&gt;::pixel_type&gt;::has_alpha == false
            - pixel_traits&lt;typename image_traits&lt;out_image_type&gt;::pixel_type&gt;::has_alpha == false 
        ensures
            - #out_img == the thresholded version of in_img (in_img is converted to a grayscale
              intensity image if it is color).  Pixels in in_img with grayscale values &gt;= thresh 
              have an output value of on_pixel and all others have a value of off_pixel.
            - #out_img.nc() == in_img.nc()
            - #out_img.nr() == in_img.nr()
    !*/</font>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='threshold_image'></a>threshold_image</b> <font face='Lucida Console'>(</font>
        image_type<font color='#5555FF'>&amp;</font> img,
        <font color='#0000FF'>typename</font> pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> image_traits<font color='#5555FF'>&lt;</font>image_type<font color='#5555FF'>&gt;</font>::pixel_type<font color='#5555FF'>&gt;</font>::basic_pixel_type thresh
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        requires
            - it is valid to call threshold_image(img,img,thresh);
        ensures
            - calls threshold_image(img,img,thresh);
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> in_image_type,
        <font color='#0000FF'>typename</font> out_image_type
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='auto_threshold_image'></a>auto_threshold_image</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> in_image_type<font color='#5555FF'>&amp;</font> in_img,
        out_image_type<font color='#5555FF'>&amp;</font> out_img
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        requires
            - in_image_type == is an implementation of array2d/array2d_kernel_abstract.h
            - out_image_type == is an implementation of array2d/array2d_kernel_abstract.h
            - pixel_traits&lt;typename image_traits&lt;in_image_type&gt;::pixel_type&gt;::max() &lt;= 65535 
            - pixel_traits&lt;typename image_traits&lt;in_image_type&gt;::pixel_type&gt;::has_alpha   == false
            - pixel_traits&lt;typename image_traits&lt;in_image_type&gt;::pixel_type&gt;::is_unsigned == true 
            - pixel_traits&lt;typename image_traits&lt;out_image_type&gt;::pixel_type&gt;::grayscale  == true  
            - pixel_traits&lt;typename image_traits&lt;out_image_type&gt;::pixel_type&gt;::has_alpha  == false 
            - pixel_traits&lt;typename image_traits&lt;out_image_type&gt;::pixel_type&gt;::is_unsigned == true 
        ensures
            - #out_img == the thresholded version of in_img (in_img is converted to a grayscale
              intensity image if it is color).  Pixels in in_img with grayscale values &gt;= thresh 
              have an output value of on_pixel and all others have a value of off_pixel.
            - The thresh value used is determined by performing a k-means clustering
              on the input image histogram with a k of 2.  The point between the two
              means found is used as the thresh value.
            - #out_img.nc() == in_img.nc()
            - #out_img.nr() == in_img.nr()
    !*/</font>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='auto_threshold_image'></a>auto_threshold_image</b> <font face='Lucida Console'>(</font>
        image_type<font color='#5555FF'>&amp;</font> img
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        requires
            - it is valid to call auto_threshold_image(img,img);
        ensures
            - calls auto_threshold_image(img,img);
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> in_image_type,
        <font color='#0000FF'>typename</font> out_image_type
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='hysteresis_threshold'></a>hysteresis_threshold</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> in_image_type<font color='#5555FF'>&amp;</font> in_img,
        out_image_type<font color='#5555FF'>&amp;</font> out_img,
        <font color='#0000FF'>typename</font> pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> image_traits<font color='#5555FF'>&lt;</font>in_image_type<font color='#5555FF'>&gt;</font>::pixel_type<font color='#5555FF'>&gt;</font>::basic_pixel_type lower_thresh,
        <font color='#0000FF'>typename</font> pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> image_traits<font color='#5555FF'>&lt;</font>in_image_type<font color='#5555FF'>&gt;</font>::pixel_type<font color='#5555FF'>&gt;</font>::basic_pixel_type upper_thresh
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        requires
            - in_image_type == is an implementation of array2d/array2d_kernel_abstract.h
            - out_image_type == is an implementation of array2d/array2d_kernel_abstract.h
            - pixel_traits&lt;typename image_traits&lt;out_image_type&gt;::pixel_type&gt;::grayscale == true  
            - pixel_traits&lt;typename image_traits&lt;in_image_type&gt;::pixel_type&gt;::has_alpha == false
            - pixel_traits&lt;typename image_traits&lt;out_image_type&gt;::pixel_type&gt;::has_alpha == false 
            - lower_thresh &lt;= upper_thresh
            - is_same_object(in_img, out_img) == false
        ensures
            - #out_img == the hysteresis thresholded version of in_img (in_img is converted to a 
              grayscale intensity image if it is color). Pixels in in_img with grayscale 
              values &gt;= upper_thresh have an output value of on_pixel and all others have a 
              value of off_pixel unless they are &gt;= lower_thresh and are connected to a pixel
              with a value &gt;= upper_thresh, in which case they have a value of on_pixel.  Here
              pixels are connected if there is a path between them composed of pixels that 
              would receive an output of on_pixel.
            - #out_img.nc() == in_img.nc()
            - #out_img.nr() == in_img.nr()
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<b>}</b>

<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_THRESHOLDINg_ABSTRACT_ 
</font>


</pre></body></html>